<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>VUE高阶组件</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
  </head>

  <body>
    <div id="app">
      <h1>{{msg}}</h1>
      <hoc msg="msg" @change="onChange()">
        <template>
          <div>I am default slot</div>
        </template>

        <div>-------------------分割线-------------------</div>

        <template v-slot:named>
          <div>I am slot</div>
        </template>
      </hoc>
    </div>
  </body>

  <script type="module">
    import getListData from './getListData.js'
    import withPromise from './hoc.js'
    
    const view = {
      template: `
            <h3>
                <div> {{ result?.name || '就不告诉你'}} </div>
                <button @click="reload">重新加载数据</button>
                <slot></slot>
                <slot name="named"></slot>
            </h3>
        `,
      data() {
        return {
          // 发送请求的时候要带上它
          requestParams: {
            name: "VUE高阶组件渲染",
          },
        };
      },

      props: ["result", "loading"],
      methods: {
        reload() {
          this.requestParams.name = '我是变化后的值'
        },
      },
    };

    let hoc = withPromise(view, getListData);
    
    var app = new Vue({
      el: "#app",
      data: {
        msg: "VUE高阶组件学习",
      },
      components: {
        hoc,
      },
      methods: {
        onChange() {},
      },
    });
  </script>
</html>
